<?php


namespace app\adminapi\logic;


use app\common\logic\BaseLogic;
use app\common\model\user\OpenvpnDept;
use app\common\service\ConfigService;
use app\common\service\FileService;
use app\common\model\user\Openvpn;


/**
 * 工作台
 * Class WorkbenchLogic
 * @package app\adminapi\logic
 */
class WorkbenchLogic extends BaseLogic
{
    /**
     * @notes 工作套
     * @param $adminInfo
     * @return array
     * @date 2021/12/29 15:58
     */
    public static function index($where)
    {
        return [
            // 今日数据
            'today' => self::today($where),
            // 近15日访客数
            'visitor' => self::visitor(),
        ];
    }


    /**
     * @notes 常用功能
     * @return array[]
     * @date 2021/12/29 16:40
     */
    public static function menu(): array
    {
        return [
            [
                'name' => '管理员',
                'image' => FileService::getFileUrl(config('project.default_image.menu_admin')),
                'url' => '/permission/admin'
            ],
            [
                'name' => '角色管理',
                'image' => FileService::getFileUrl(config('project.default_image.menu_role')),
                'url' => '/permission/role'
            ],
            [
                'name' => '部门管理',
                'image' => FileService::getFileUrl(config('project.default_image.menu_dept')),
                'url' => '/organization/department'
            ],
            [
                'name' => '字典管理',
                'image' => FileService::getFileUrl(config('project.default_image.menu_dict')),
                'url' => '/dev_tools/dict'
            ],
            [
                'name' => '代码生成器',
                'image' => FileService::getFileUrl(config('project.default_image.menu_generator')),
                'url' => '/dev_tools/code'
            ],
            [
                'name' => '素材中心',
                'image' => FileService::getFileUrl(config('project.default_image.menu_file')),
                'url' => '/material/index'
            ],
            [
                'name' => '菜单权限',
                'image' => FileService::getFileUrl(config('project.default_image.menu_auth')),
                'url' => '/permission/menu'
            ],
            [
                'name' => '网站信息',
                'image' => FileService::getFileUrl(config('project.default_image.menu_web')),
                'url' => '/setting/website/information'
            ],
        ];
    }


    /**
     * @notes 今日数据
     * @return int[]
     * @date 2021/12/29 16:15
     */
    public static function today($where): array
    {

        $all = Openvpn::where($where)->count();
        $online = Openvpn::where($where)->where('status', 1)->count();
        $offline = Openvpn::where($where)->where('status', 0)->count();
        $warn = Openvpn::where($where)->where('status', 1)->whereLike('vpn_ip', '10.20.0.%')->count();
        return [
            'time' => date('Y-m-d H:i:s'),
            'all' => $all,
            'online' => $online,
            'offline' => $offline,
            'warn' => $warn
        ];
    }


    /**
     * @notes 访问数
     * @return array
     * @date 2021/12/29 16:57
     */
    public static function visitor(): array
    {
        $num = [];
        $date = [];
        for ($i = 0; $i < 31; $i++) {
            $where_start = strtotime("- " . $i . "day");
            $date[] = date('Y/m/d', $where_start);
            $num[$i] = rand(0, 100);
        }

        return [
            'date' => $date,
            'list' => [
                ['name' => '设备数', 'data' => $num]
            ]
        ];
    }


    /**
     * @notes 服务支持
     * @return array[]
     * @date 2022/7/18 11:18
     */
    public static function support()
    {
        return [
            [
                'image' => FileService::getFileUrl(config('project.default_image.qq_group')),
                'title' => '官方公众号',
                'desc' => '关注官方公众号',
            ],
            [
                'image' => FileService::getFileUrl(config('project.default_image.customer_service')),
                'title' => '添加企业客服微信',
                'desc' => '想了解更多请添加客服',
            ]
        ];
    }

}